<?php

namespace app\commons;

trait SingleInstanceTrait
{
    /**
     * 单例模式
     * @var obj
     */
    private static $_instance = [];

    /**
     * 获取单例实例化对象
     * @return static
     */
    public static function getInstance(...$args)
    {
        $class = static::class;
        if (!isset(self::$_instance[$class])) {
            self::$_instance[$class] = new $class(...$args);
        }
        return self::$_instance[$class];
    }
}
